import { database } from "@/drizzle";
import { ETaskPriority, taskEntity } from "@/drizzle/model/taskEntity";
import { DateTimePicker } from "react-native-ui-lib";

const useChangeTimer = (date: Date, timer: Date, mode: React.ComponentProps<typeof DateTimePicker>["mode"]) => {
  let dateTimerNew = timer;
  if (mode === "date") {
    dateTimerNew.setFullYear(date.getFullYear());
    dateTimerNew.setMonth(date.getMonth());
    dateTimerNew.setDate(date.getDate());
  } else if (mode === "time") {
    dateTimerNew.setHours(date.getHours());
    dateTimerNew.setMinutes(date.getMinutes());
    dateTimerNew.setSeconds(date.getSeconds());
  }
  return dateTimerNew;
};

const useInsertForm = database.insert(taskEntity);
const useUpdateForm = database.update(taskEntity);

export { useChangeTimer, useInsertForm, useUpdateForm };
